home *** CD-ROM | disk | FTP | other *** search
-
- /*
- Application Shell -- Version 1.00 -- Nov 5, 1989
-
- Copyright (c) 1989 by Neal E. Trautman
-
- 'ShareWare' -- Please send $5 contribution to:
- Neal Trautman
- 1701 S.W. 42nd Street
- Fargo, ND 58103
-
- This is a simple application shell.
- */
-
- #define APPL_NAME "\pApplication Shell"
- #define date "\p11/5/89"
- #define version "\pv1.00"
-
- #define line1 "\p by Neal E. Trautman"
- #define line2 "\p'ShareWare'"
- #define line3 "\pPlease send $5 contribution to:"
- #define line4 "\pNeal Trautman"
- #define line5 "\p1701 S.W. 42nd Street"
- #define line6 "\pFargo, ND 58103"
- #define line7 version
- #define line8 date
-
- #define WINDOWWIDTH (INSET + 400 + INSET)
- #define WINDOWHEIGHT (INSET + 200 + INSET)
- #define WINDOWTOP 40
- #define WINDOWLEFT 2
-
- #define FAST register
- #define NULL 0L
- #define MAXLONG 0xFFFFFFFFL
- #define BUTTON_OFF 0
- #define BUTTON_ON 1
- #define INSET 4
-
- #define _Unimplemented 0xA89F /* UnImplementedCore Routine Trap Number */
- #define _WaitNextEvent 0xA860 /* WaitNextEvent Trap Number */
-
- #define APPLE_ID 100
- #define FILE_ID 101
- #define EDIT_ID 102
-
- enum {
- A_ABOUT = 1
- };
-
- enum {
- F_NEW = 1,
- F_OPEN,
- F_CLOSE,
- F_ULINE1,
- F_SAVE,
- F_SAVEAS,
- F_REVERT,
- F_ULINE2,
- F_PSETUP,
- F_PRINT,
- F_ULINE3,
- F_QUIT
- };
-
- enum {
- E_UNDO = 1,
- E_ULINE1,
- E_CUT,
- E_COPY,
- E_PASTE
- };
-
- Boolean Done,HasWNE;
- Rect screenBounds;
- SysEnvRec MacInfo;
- WindowPtr Window1 = NULL;
-
- #define pstrlen(ps) (int)(ps[0])
- #define pcharcat(ps,ch) ps[++(ps[0])] = ch
-
- static void pstrcpy(d, s)
- StringPtr d, s;
- {
- BlockMove(s, d, s[0] + 1);
- }
-
- static void pstrcat(d, s)
- StringPtr d, s;
- {
- BlockMove(s+1, d+(d[0])+1, s[0]);
- d[0] += s[0];
- }
-
-
- static Boolean NextEvent(eventMask,theEvent)
- int eventMask;
- EventRecord *theEvent;
- {
- if (HasWNE)
- {
- return(WaitNextEvent(eventMask,theEvent,0L,NULL));
- }
- else
- {
- SystemTask();
- return(GetNextEvent(eventMask,theEvent));
- }
- }
-
- #define doline(line) \
- { MoveTo (rct.left + (rct.right - rct.left - StringWidth (line)) / 2,linev); \
- DrawString (line); \
- linev += lineinc; }
-
- static void drawabout(w)
- WindowPtr w;
- {
- Str255 str;
- Rect rct;
- FAST int linev,lineinc;
-
- linev = INSET + 20;
- lineinc = INSET + 10;
- rct = w->portRect;
- InsetRect (&rct, INSET, INSET);
- TextFont (systemFont);
- TextSize (0);
- pstrcpy(str,APPL_NAME);
- pstrcat(str,line1);
- doline (str);
- TextFont (geneva);
- TextSize (9);
- doline ("\p");
- doline (line2);
- doline (line3);
- TextFace(bold);
- doline (line4);
- doline (line5);
- doline (line6);
- TextFace(0);
- MoveTo (rct.left + INSET, rct.bottom - INSET);
- DrawString (line7);
- MoveTo (rct.right - INSET - StringWidth (line8), rct.bottom - INSET);
- DrawString (line8);
- }
-
- static void doAbout()
- {
- FAST WindowPtr w;
- EventRecord evt;
- Boolean done;
- int h,v;
- Rect r;
-
- InitCursor ();
- SetRect (&r, 0, 0, 240, 120);
- w = NewWindow (NULL, &r, "\p", FALSE, dBoxProc, -1L, FALSE, 0);
- SetPort (w);
- h = screenBounds.left + (((screenBounds.right - screenBounds.left) -
- (w->portRect.right - w->portRect.left)) / 2);
- v = screenBounds.top + (((screenBounds.bottom - screenBounds.top) -
- (w->portRect.bottom - w->portRect.top)) / 3);
- MoveWindow (w, h, v, FALSE);
- ShowWindow (w);
- /* drawabout (w); */
- done = FALSE;
- while (!done)
- {
- if (NextEvent (everyEvent, &evt))
- switch (evt.what)
- {
- case mouseDown:
- while (WaitMouseUp())
- ; /* and fall thru... */
- case mouseUp:
- case keyDown:
- case autoKey:
- done = TRUE;
- break;
- case updateEvt:
- if ((WindowPtr)(evt.message) == w)
- {
- SetPort (w);
- BeginUpdate (w);
- drawabout (w);
- EndUpdate (w);
- }
- break;
- }
- }
- DisposeWindow (w);
- FlushEvents (mDownMask+mUpMask+keyDownMask+keyUpMask+autoKeyMask,0);
- }
-
- static void DrawWindow(w)
- WindowPtr w;
- {
- if (w == Window1)
- {
- EraseRect(&w->portRect);
- DrawGrowIcon(w);
- TextFont (systemFont);
- TextSize (0);
- MoveTo (w->portRect.left +
- (w->portRect.right - w->portRect.left - StringWidth (APPL_NAME)) / 2,
- w->portRect.top + (w->portRect.bottom - w->portRect.top) / 2);
- DrawString(APPL_NAME);
- }
- }
-
- static void OpenWindow1()
- {
- Rect windowRect;
-
- SetRect(&windowRect, WINDOWLEFT, WINDOWTOP,
- WINDOWLEFT + WINDOWWIDTH, WINDOWTOP + WINDOWHEIGHT);
- Window1 = NewWindow(NULL, &windowRect, APPL_NAME, TRUE, zoomDocProc, -1, TRUE, NULL);
- SetPort(Window1);
- }
-
- static void DoCloseWindow(window)
- WindowPtr window;
- {
- if (((WindowPeek)window)->windowKind < 0)
- CloseDeskAcc(((WindowPeek)window)->windowKind);
- else
- DisposeWindow(window);
- }
-
- static void SetupMenus()
- {
- FAST MenuHandle Menu;
- Str255 s;
-
- s[0] = 1;
- s[1] = appleMark;
- Menu = NewMenu(APPLE_ID,s);
- pstrcpy(s,"\pAbout ");
- pstrcat(s,APPL_NAME);
- pstrcat(s,"\p…/`;(-");
- AppendMenu(Menu,s);
- AddResMenu(Menu,'DRVR');
- InsertMenu(Menu,APPLE_ID);
- Menu = NewMenu(FILE_ID,"\pFile");
- AppendMenu(Menu,
- "\pNew/N;Open…/O;Close/W;(-;Save/S;Save As…/A;Revert/R;(-;Page Setup…;Print…/P;(-;Quit/Q");
- InsertMenu(Menu,FILE_ID);
- Menu = NewMenu(EDIT_ID,"\pEdit");
- AppendMenu(Menu,"\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
- InsertMenu(Menu,EDIT_ID);
- DrawMenuBar();
- }
-
- pascal void resumeProc()
- {
- ExitToShell();
- }
-
- static Boolean InitMac()
- {
- FAST int i;
- EventRecord theEvent;
- int message,count;
- AppFile applfile;
-
- MaxApplZone();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- InitGraf (&thePort);
- InitFonts ();
- InitWindows ();
- InitDialogs (resumeProc);
- TEInit ();
- InitMenus ();
- InitCursor ();
-
- /* use screenBits.bounds to get all gDevices */
- screenBounds = screenBits.bounds;
- screenBounds.top += GetMBarHeight();
- InsetRect(&screenBounds,INSET,INSET);
-
- HasWNE = (Boolean)
- ((NGetTrapAddress(_WaitNextEvent,ToolTrap)) != (GetTrapAddress(_Unimplemented)));
- if (HasWNE)
- { /* if Juggler, call WaitNextEvent() so our window comes up in front */
- i = 8;
- while (--i >= 0)
- NextEvent(everyEvent,&theEvent);
- }
- FlushEvents (everyEvent,0);
-
- SysEnvirons(1, &MacInfo);
- if (MacInfo.machineType <= envMac)
- return(FALSE);
- if (MacInfo.systemVersion < 0x0420)
- return(FALSE);
-
- CountAppFiles(&message,&count);
- if (count > 0)
- {
- for (i = 1; i <= count; i++)
- {
- GetAppFiles(i,&applfile);
- /* do something with message and file */
- }
- }
-
- SetupMenus();
- OpenWindow1();
-
- return(TRUE);
- }
-
- static void HandleMenu(menuResult)
- long menuResult;
- {
- int menu,item;
- char result;
- Str255 daName;
- GrafPtr savePort;
-
- menu = HiWord(menuResult);
- item = LoWord(menuResult);
- switch (menu)
- {
- case APPLE_ID:
- {
- if (item == A_ABOUT)
- doAbout();
- else
- {
- GetItem(GetMHandle(APPLE_ID), item, &daName);
- GetPort(&savePort);
- OpenDeskAcc(&daName);
- SetPort(savePort);
- }
- break;
- }
- case FILE_ID:
- {
- switch (item)
- {
- case F_NEW:
- {
- break;
- }
- case F_OPEN:
- {
- break;
- }
- case F_CLOSE:
- {
- break;
- }
- case F_SAVE:
- {
- break;
- }
- case F_SAVEAS:
- {
- break;
- }
- case F_REVERT:
- {
- break;
- }
- case F_PSETUP:
- {
- break;
- }
- case F_PRINT:
- {
- break;
- }
- case F_QUIT:
- {
- Done = TRUE;
- break;
- }
- }
- break;
- }
- case EDIT_ID:
- {
- if (!SystemEdit(item - 1))
- {
- switch(item)
- {
- case E_UNDO:
- case E_CUT:
- case E_COPY:
- case E_PASTE:
- {
- SysBeep(2L);
- break;
- }
- }
- }
- break;
- }
- }
- HiliteMenu(0);
- }
-
- static void HandleMouseUp(theEvent)
- EventRecord *theEvent;
- {
- }
-
- static void HandleContent(theEvent,window)
- EventRecord *theEvent;
- WindowPtr window;
- {
- }
-
- static void HandleMouseDown(theEvent)
- FAST EventRecord *theEvent;
- {
- WindowPtr mwdw;
- Rect growrect;
- FAST int wherecode;
- FAST long tmplong;
- FAST WindowPtr mouseWindow;
-
- wherecode = FindWindow(theEvent->where,&mwdw);
- mouseWindow = mwdw;
- switch(wherecode)
- {
- case inMenuBar:
- {
- HandleMenu(MenuSelect(theEvent->where));
- break;
- }
-
- case inSysWindow:
- {
- SystemClick(theEvent,mouseWindow);
- break;
- }
-
- case inContent:
- {
- if (mouseWindow != FrontWindow())
- SelectWindow(mouseWindow);
- HandleContent(theEvent,mouseWindow);
- break;
- }
-
- case inDrag:
- {
- DragWindow(mouseWindow,theEvent->where,&screenBounds);
- break;
- }
-
- case inGoAway:
- {
- if (TrackGoAway(mouseWindow,theEvent->where))
- DoCloseWindow(mouseWindow);
- break;
- }
-
- case inGrow:
- {
- if (mouseWindow != FrontWindow())
- {
- SelectWindow(mouseWindow);
- }
- else
- {
- if (theEvent->modifiers & optionKey)
- ZoomWindow(mouseWindow,inZoomOut,TRUE);
- else
- {
- SetRect(&growrect,75,75,32000,32000);
- tmplong = GrowWindow(mouseWindow, theEvent->where, &growrect);
- if (tmplong != 0)
- {
- SetPort(mouseWindow);
- InvalRect(&mouseWindow->portRect);
- SizeWindow(mouseWindow, LoWord(tmplong), HiWord(tmplong), TRUE);
- }
- }
- }
- break;
- }
-
- case inZoomIn:
- case inZoomOut:
- {
- if (TrackBox(mouseWindow,theEvent->where,wherecode))
- ZoomWindow(mouseWindow,wherecode,TRUE);
- break;
- }
- }
- }
-
- static void HandleKeyBoard(theEvent)
- EventRecord *theEvent;
- {
- char ch;
-
- ch = (char)(theEvent->message & charCodeMask);
- }
-
- static void HandleUpdate(theEvent)
- EventRecord *theEvent;
- {
- FAST WindowPtr window;
-
- window = (WindowPtr)theEvent->message;
- SetPort(window);
- BeginUpdate(window);
- DrawWindow(window);
- EndUpdate(window);
- }
-
- static void HandleActivate(theEvent)
- EventRecord *theEvent;
- {
- WindowPtr window;
- Boolean doActive;
-
- window = (WindowPtr)theEvent->message;
- doActive = ((theEvent->modifiers & activeFlag) != 0);
- DrawGrowIcon(window);
- }
-
- static void HandleDisk(theEvent)
- EventRecord *theEvent;
- {
- Point where;
-
- if (HiWord(theEvent->message) != noErr)
- {
- DILoad();
- SetPt(&where, 115, 70);
- DIBadMount(where,theEvent->message);
- DIUnload();
- }
- }
-
- static void HandleNull(theEvent)
- EventRecord *theEvent;
- {
- }
-
- static void doEvent()
- {
- EventRecord theEventRecord;
- FAST EventRecord *theEvent = &theEventRecord;
-
- NextEvent(everyEvent,theEvent);
- switch (theEvent->what)
- {
- case mouseDown:
- {
- HandleMouseDown(theEvent);
- break;
- }
- case mouseUp:
- {
- HandleMouseUp(theEvent);
- break;
- }
- case keyDown:
- case autoKey:
- {
- if (theEvent->modifiers & cmdKey)
- HandleMenu(MenuKey((char)(theEvent->message & charCodeMask)));
- else
- HandleKeyBoard(theEvent);
- break;
- }
- case updateEvt:
- {
- HandleUpdate(theEvent);
- break;
- }
- case activateEvt:
- {
- HandleActivate(theEvent);
- break;
- }
- case diskEvt:
- {
- HandleDisk(theEvent);
- break;
- }
- case nullEvent:
- {
- HandleNull(theEvent);
- break;
- }
- }
- }
-
- void main()
- {
- if (InitMac())
- {
- Done = FALSE;
- while(!Done)
- doEvent();
- }
- else
- SysBeep(2L);
- }
-
-